package com.taichuan.selfcheck.ui.activity.base;

import android.util.Log;
import android.view.KeyEvent;
import com.taichuan.keysupport.KeySupport;
import com.taichuan.keysupport.Observer;
import com.taichuan.keysupport.ViewFocus;
import com.taichuan.mvp.base.MvpBaseInterface;
import com.taichuan.mvp.base.MvpBasePresenter;

import org.greenrobot.eventbus.Subscribe;

/**
 * Created by OISNY on 2016/8/22.
 */
public abstract class KeySupportBaseActivity<V extends MvpBaseInterface, P extends MvpBasePresenter<V>> extends AppBaseActivity<V, P> implements Observer {

    protected KeySupport mKeySupport = new KeySupport(this);
    protected ViewFocus mViewFocus = new ViewFocus();

    @Override
    protected void onResume() {
        super.onResume();
        //TODO 改用EventBus订阅按键事件，待实现
//        InterfaceBus.getDefault().register(mKeyboardSubscription, EventDefine.KEYBOARD);
    }

    @Override
    protected void onPause() {
        super.onPause();
        //TODO 改用EventBus注销按键事件，待实现
//        InterfaceBus.getDefault().unregister(mKeyboardSubscription);
    }

    /**
     * TODO
     *  因JDK1.5 的特性 参数设置为对象
     * @param keyCode
     */
    @Subscribe
    public void receiveKeyEvent(Integer keyCode){
        mKeySupport.input(keyCode);
    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        resumeAutoFinishTimer();
        return super.dispatchKeyEvent(event);
    }

    @Override
    public void onConvertKeyEvent(int keyCode, KeyEvent keyEvent) {
        //触发了按键事件接口，当前设备类型为按键机型
        isTouchDevice = false;
        dispatchKeyEvent(keyEvent);
    }
}
